﻿using CSharpTestProject.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharpTestProject.AdminFormFolder
{
    public partial class DeleteStudentForm : Form
    {
        public _Sql sql;
        public DeleteStudentForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string id;
            string name;
            string bj;
            string kcm;
            string s = "SELECT * FROM students WHERE";
            if (textBox1.Text != "")
            {
                id = textBox1.Text;
                s += $" xh='{id}' AND";
            }
            if (textBox2.Text != "")
            {
                name = textBox2.Text;
                s += $" name='{name}' AND";
            }
            if (textBox3.Text != "")
            {
                bj = textBox3.Text;
                s += $" bj='{bj}' AND";
            }
            if (textBox4.Text != "")
            {
                kcm = textBox4.Text;
                s += $" kcm='{kcm}' AND";
            }
            s = s.Substring(0, s.Length - 3);
            DataSet dataSet = sql.SqlFind(s);
            DataTable data = dataSet.Tables[0];
            for(int i=0;i<data.Rows.Count; i++)
            {
                DataRow row = data.Rows[i];
                string message = $"学号：{row[1]}\n姓名：{row[2]}\n班级：{row[3]}\n课程名：{row[4]}\n是否删除？";
                DialogResult dr = MessageBox.Show(message, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    string s1 = $"delete students where xh='{row[1]}' AND name='{row[2]}' AND " +
                        $"bj='{row[3]}' AND kcm='{row[4]}'";
                    bool b = sql.ManageData(s1);
                    if (b)
                    {
                        MessageBox.Show("删除成功！");
                        break;
                    }
                }
            }
        }
    }
}
